dojo.require("dojo.widget.AccordionContainer");

var container = document.getElementById(widget.uuid);

var accordion = dojo.widget.createWidget("AccordionContainer", null, container);
var rows = [];
// pull in the arguments
if (typeof widget.value != "undefined") {
  
  // convert the rows object into an array
  if (typeof widget.value.rows == "object") {
      for (var i in widget.value.rows) {
        var row = [];
        for (var ir in widget.value.rows[i] ) {  
            row[ir] = widget.value.rows[i][ir];
        }
        rows.push(row);
      }
  }
} else {
    rows = [
                {label: 'Books', content: 'Book content'},
                {label: 'Magazines', content: 'Magazines here'},
                {label: 'Newspaper', content: 'Newspaper content'}
            ];
}

for(i=0; i<rows.length; ++i) {
    var _row = rows[i];
    if (typeof _row.url == 'undefined') {
        var content = dojo.widget.createWidget("ContentPane", {label: rows[i].label, selected: i==1});
        content.setContent(_row.content);
        accordion.addChild(content);
    } else {
        var callback = function(xhr) {
          if (xhr.readyState == 4) {
            var _c = dojo.widget.createWidget("ContentPane", {label: _row.label, selected: i==1});
                    _c.setContent(xhr.responseText);
                    accordion.addChild(_c);
                    
          }
        }
        // go out and fetch the url synchronously

        var xhr = jmaki.doAjax({
            method:"GET",
            url: _row.url,
            asynchronous: false,
            callback: callback
           }
           );
    }
    
}
accordion.onResized();
jmaki.attributes.put(widget.uuid, accordion);